using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class LevelGroups : ScriptableObject, IEnumerable<LevelGroup>
{
    public const string DEFAULT_NAME = nameof(LevelGroups);
    public static LevelGroups Default => Resources.Load<LevelGroups>(DEFAULT_NAME);

    [SerializeField]private List<LevelGroup> _groups = new List<LevelGroup>();

    public IEnumerator<LevelGroup> GetEnumerator()
    {
        return _groups.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }

    public void Save()
    {
#if UNITY_EDITOR
        UnityEditor.EditorUtility.SetDirty(this);
#endif
    }

#if UNITY_EDITOR
    [UnityEditor.MenuItem("MyGames/Level Groups")]
    public static void Open()
    {
        GamePlayEditorManager.OpenScriptableAtDefault<LevelGroups>();
    }
#endif
}

[Serializable]
public class LevelGroup:IEnumerable<Level>
{
    public string id;
    public string name;
    public Color pieceColor;
    public Color lineColor;
   
    public List<Level> levels;
 
    public IEnumerator<Level> GetEnumerator()
    {
        return levels?.GetEnumerator() ?? Enumerable.Empty<Level>().GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
}